using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using Framework.Library;
using Framework.Library.Components;
using Framework.Module.CMS.Library.Definitions;
using Framework.Module.CMS.Library.Providers;

namespace Framework.Module.CMS.Library.Contents
{
	public class ContentController
	{
		private const string key = "Framework.Portal.CMS.Content";

        public static int AddContent(ContentInfo content)
        {
            int id = DataAccessProvider.Instance().AddContent(content);
            DataCaching data = new DataCaching();
            data.RemoveCache(key);
            return id;
        }
        public static ContentInfo GetInfo(int contentID)
        {
            ContentInfo info;
            info = DataAccessProvider.Instance().GetInfo(contentID);
            return info;
        }
        public static DataTable GetContents()
        {
            string param = "GetContents";
            DataCaching data = new DataCaching();
            DataTable dtContents = (DataTable)data.GetHashCache(key, param);
            if (dtContents != null) return dtContents;
            dtContents = DataAccessProvider.Instance().GetContents();
            data.SetHashCache(key, param, AppEnv.CacheExpire_Content, dtContents);
            return dtContents;
        }
        public static DataTable GetContents(int zoneId, int status, int userId)
        {
            //string param = "GetContents_" + zoneId.ToString() + "_" + status.ToString() + "_" + userId;
            //DataCaching data = new DataCaching();
            DataTable dtContents ;//= (DataTable)data.GetHashCache(key, param);
           // if (dtContents != null) return dtContents;
            dtContents = DataAccessProvider.Instance().GetContents(zoneId, status, userId);
            //data.SetHashCache(key, param, Constants.CacheExpire_Content, dtContents);
            return dtContents;
        }
        public static DataTable GetContents(int zoneId, int status)
        {
            //string param = "GetContents_" + zoneId.ToString() + "_" + status.ToString() + "_" + userId;
            //DataCaching data = new DataCaching();
            DataTable dtContents;//= (DataTable)data.GetHashCache(key, param);
            // if (dtContents != null) return dtContents;
            dtContents = DataAccessProvider.Instance().GetContents(zoneId, status);
            //data.SetHashCache(key, param, Constants.CacheExpire_Content, dtContents);
            return dtContents;
        }
        public static void SetContentStatus(int contentId, int status)
        {
            DataAccessProvider.Instance().SetContentStatus(contentId, status);
        }
        public static void DeleteContent(int contentId)
        {
            DataAccessProvider.Instance().DeleteContent(contentId);
            DataCaching data = new DataCaching();
            data.RemoveCache(key);
        }
        public static void SetContentComment(int contentId, string comment)
        {
            DataAccessProvider.Instance().SetContentComment(contentId, comment);
        }
        public static void LockContent(int contentId, int userId)
        {
            DataAccessProvider.Instance().LockContent(contentId, userId);
        }
        public static void UpdateContent(ContentInfo _contentInfo)
        {
            DataAccessProvider.Instance().UpdateContent(_contentInfo);
        }
        public static void UnLockContent(int contentId)
        {
            DataAccessProvider.Instance().UnLockContent(contentId);
        }
        
        public static ContentInfo GetContent(int contentId)
        {
            return DataAccessProvider.Instance().GetContent(contentId);
        }
        public static DataTable GetContentsInContentList(int zoneId, int portalId)
        {
            DataTable dtContents = DataAccessProvider.Instance().GetContentsInContentList(zoneId, portalId);
            return dtContents;
        }
	}
}
